<template>
  <a-card :bordered="false">
    <!-- <transition name="fade" v-if="showImg">-->
    <div class="img-view" v-if="showImg">
      <!-- 遮罩层 -->
      <div class="img-layer" v-if="showImg" @click="viewImg"></div>

      <div  v-show="jianShow">
        <img :src="leftjian" class="left" @click="handleClickLeft"/>
      </div>

      <div class="img" v-if="showImg" @click="viewImg" >
        <img :src="imgSrc[imgIndex]">
      </div>

      <div v-show="jianShow">
        <img :src="jiantou" class="right" @click="handleClickRight"/>
      </div>

    </div>
    <!--</transition>-->
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="活动编码">
              <a-input placeholder="请输入活动编码" v-model="queryParam.actCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="活动名称">
              <a-input placeholder="请输入活动名称" v-model="queryParam.actName"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="活动时间">
                <a-range-picker format="YYYY-MM-DD" v-model="queryParam.actDateStr" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="门店清单">
                <a-select v-model="queryParam.haveTerm" placeholder="请选择" :allowClear="true" >
                  <a-select-option value="">请选择</a-select-option>
                  <a-select-option value="0">无</a-select-option>
                  <a-select-option value="1">有</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <template slot="imgPathS" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="record.actFileUrl" @click="clickImg(record.actFileUrl)"/>
          </div>

        </template>
        <template slot="titleShow" slot-scope="text, record, index">
          <div class="smileDark" :title="record.actContent">{{ record.actContent }}</div>
        </template>
        <template slot="execShow" slot-scope="text, record, index">
          <div class="smileDark" :title="record.actExecNeeds">{{ record.actExecNeeds }}</div>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <tpmActSpecial-modal ref="modalForm" @ok="modalFormOk"></tpmActSpecial-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import TpmActSpecialModal from './modules/TpmActSpecialModal'
import { PageListMixin } from '@/mixins/PageListMixin'

export default {
  name: 'TpmActSpecialList',
  mixins: [PageListMixin],
  components: {
    TpmActSpecialModal
  },
  data() {
    return {
      jianShow: '',
      leftjian: require('@/assets/leftjian.png'),
      jiantou: require('@/assets/jiantou.png'),
      message: '',
      imgIndex:0,
      showImg: false,
      imgSrc: [],
      description: '专项活动管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        }
        ,
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        },
        {
          title: '活动编号',
          align: 'center',
          dataIndex: 'actCode'
        },
        {
          title: '活动名称',
          align: 'center',
          dataIndex: 'actName'
        },
        {
          title: '活动开始时间',
          align: 'center',
          dataIndex: 'actStart'
        },
        {
          title: '活动结束时间',
          align: 'center',
          dataIndex: 'actEnd'
        },
        {
          title: '活动内容',
          align: 'center',
          width: 200,
          dataIndex: 'actContent',
          scopedSlots: { customRender: 'titleShow' },
        },
        {
          title: '执行要求',
          align: 'center',
          width: 200,
          dataIndex: 'actExecNeeds',
          scopedSlots: { customRender: 'execShow' },

        },
        {
          title: '采集项目',
          align: 'center',
          dataIndex: 'actCollectionsName'
        },
        {
          title: '有无门店清单',
          align: 'center',
          dataIndex: 'haveTerm',
          customRender: function (text) {
            if (text === 0) {
              return '无'
            } else {
              return '有'
            }
          }
        },
        {
          title: '示例文件',
          align: 'center',
          dataIndex: 'actFileUrl',
          scopedSlots: {customRender: 'imgPathS'}
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remarks'
        }
      ],
      url: {
        list: window._CONFIG['domianTpmURL']+'/act/tpmActSpecial/findPageList',
        delete: window._CONFIG['domianTpmURL']+'/act/tpmActSpecial/delete',
        deleteBatch: window._CONFIG['domianTpmURL']+'/act/tpmActSpecial/deleteBatch',
        exportXlsUrl: 'act/tpmActSpecial/exportXls',
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianTpmURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    clickImg(path) {

      this.imgIndex = 0;
      //console.log(path);
      this.showImg = true;
      // 获取当前图片地址
      this.imgSrc = []
      this.imgSrc.push(path);
      //console.log(this.imgSrc)
      this.jianShow = false;
      if (path.length>1){
        this.jianShow = true;
        // console.log(this.jianShow);
      }
    },
    viewImg() {
      this.showImg = false;
    },
    handleClickLeft(){
      if(this.imgIndex===0){
        this.imgIndex=(this.imgSrc.length)-1;
        return
      }
      if(this.imgIndex<this.imgSrc.length && this.imgIndex!==0){
        this.imgIndex--;
        return
      }
    },
    handleClickRight(){
      if(this.imgIndex<(this.imgSrc.length-1)){
        this.imgIndex++;
        return
      }
      if(this.imgIndex===(this.imgSrc.length-1)){
        this.imgIndex=0;
        return
      }

    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
/*动画*/
.fade-enter-active,
.fade-leave-active {
  transition: all .2s linear;
  transform: translate3D(0, 0, 0);
}

.fade-enter,
.fade-leave-active {
  transform: translate3D(100%, 0, 0);
}

/* bigimg */

.img-view {
  position: relative;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

/*遮罩层样式*/
.img-view .img-layer {
  position: fixed;
  z-index: 99998;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.7);
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/*不限制图片大小，实现居中*/
.img-view .img img {
  position: absolute;
  min-width: 50%;
  max-width: 50%;
  display: block;
  left: 0;
  right: 0;
  margin: auto;
  z-index: 99999;
}
.left {
  position: absolute;
  min-width: 5%;
  max-width: 5%;
  display: block;
  left: 0px;
  margin: auto;
  z-index: 99999;
  top: 110px;
}
.right {
  position: absolute;
  min-width: 5%;
  max-width: 5%;
  display: block;
  right: 0px;top: 110px;
  margin: auto;
  z-index: 99999;
}
.shenpito {
  color: #434e59;
}
.shenpion{
  color: #2eabff;
}
.smileDark {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  width: 180px;
}
</style>